package tpenchere.ui.model;

import javax.swing.JTextField;
import javax.swing.RowFilter;
import javax.swing.table.TableModel;

public class ProductRowFilter extends RowFilter<TableModel, Integer> {
	
	JTextField searchField;
	
	public ProductRowFilter(JTextField searchField) {
		this.searchField = searchField;
	}
	
	@Override
	public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
		ProductTableModel tableModel = (ProductTableModel) entry.getModel();
		if(searchField.getText() == null || searchField.getText().length() == 0) {
			return true;
		} else {
			return tableModel.getCategory(entry.getIdentifier()).startsWith(searchField.getText());					
		}	
	}

	public JTextField getSearchField() {
		return searchField;
	}

	public void setSearchField(JTextField searchField) {
		this.searchField = searchField;
	}

}
